/**
 *@author 易涛
 *@version 1.0
 */
Date.prototype.Format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份   
		"d+": this.getDate(), //日
		"h+": this.getHours(), //小时   
		"m+": this.getMinutes(), //分   
		"s+": this.getSeconds(), //秒   
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度   
		"S": this.getMilliseconds() //毫秒   
	};
	if(/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for(var k in o)
		if(new RegExp("(" + k + ")").test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
};
$(function() {
	//加载datepicker类
	$(".form_datetime").datetimepicker({
		format: 'yyyy-mm-dd', //显示格式
		todayHighlight: 1, //今天高亮
		minView: "month", //设置只显示到月份
		startView: 2,
		forceParse: 0,
		showMeridian: 1,
		autoclose: 1 //选择后自动关闭
	});

});

/**
 * 计算两个日期之间的天数
 * @param sDate1
 * @param sDate2
 * @returns
 */
function datedifference(sDate1, sDate2) {
	//sDate1和sDate2是2006-12-18格式  
	var dateSpan, tempDate, iDays;
	sDate1 = Date.parse(sDate1);
	sDate2 = Date.parse(sDate2);
	dateSpan = sDate2 - sDate1;
	dateSpan = Math.abs(dateSpan);
	iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
	return iDays
};

//重置
$('#reset').click(function() {
	alert(11);
	$("#driverName").val("");
	$("#cellPhone").val("");
	$("#birthday").val("");
	$("#idcard").val("");
	$("#idcardPath").val("");
	$("#drivingLicence").val("");
	$("#drivingAge").val("");
	$("#drivingLicencePath").val("");
});

//提交数据
$('#submitBtn').click(function() {
	var driverName = $("#driverName").val();
	var cellPhone = $("#cellPhone").val();
	var birthday = $("#birthday").val();
	var idcard = $("#idcard").val();
	var idcardPath = $("#idcardPath").val();
	var drivingLicence = $("#drivingLicence").val();
	var drivingAge = $("#drivingAge").val();
	var drivingLicencePath = $("#drivingLicencePath").val();
	
	if(driverName == "") {
		$.tips({
			content: "请输入司机姓名",
			autoClose: 'cancel|3000'
		});
		return;
	}
	if(cellPhone == "") {
		$.tips({
			content: "请输入司机联系电话",
			autoClose: 'cancel|3000'
		});
		return;
	}
	if(birthday == "") {
		$.tips({
			content: "请选择司机出生日期",
			autoClose: 'cancel|3000'
		});
		return;
	}
	if(idcard == "") {
		$.tips({
			content: "请输入身份证号",
			autoClose: 'cancel|3000'
		});
		return;
	}

	if(idcardPath == "") {
		$.tips({
			content: "请上传身份证照片",
			autoClose: 'cancel|3000'
		});
		return;
	}
	if(drivingLicence == "") {
		$.tips({
			content: "请输入驾驶证编号",
			autoClose: 'cancel|3000'
		});
		return;
	}
	if(drivingAge == "") {
		$.tips({
			content: "请输入司机驾龄",
			autoClose: 'cancel|3000'
		});
		return;
	}
	if(drivingLicencePath == "") {
		$.tips({
			content: "请上传驾驶证图片",
			autoClose: 'cancel|3000'
		});
		return;
	}

	//显示对话框模型
	$("#addDialog").modal('show');
	window.setTimeout(function (){
		$("#addDialog").modal('hide');
		$.tips({
  				content : "数据提交成功！",
  				autoClose : 'cancel|3000'
  		});
  		window.location.reload();
	},5000);
});

